home *** CD-ROM | disk | FTP | other *** search
- /*****
- * bullseye.c
- *
- * A simple demonstration program to play with the debugger
- *
- *
- *****/
-
- #include "samplerMenus.h"
- #include "samplerWindow.h"
- #include "samplerControls.h"
- #include "number_picker.h"
-
- extern WindowPtr samplerWindow;
- extern ControlHandle rocketCntl, timeButtonCntl, timeCntl, dateCntl, numberCntl;
- extern Rect dragRect;
-
- SysEnvRec gMac;
-
- void InitMacintosh(void);
- void HandleMouseDown (EventRecord *theEvent);
- void HandleEvent(void);
-
- /****
- * InitMacintosh()
- *
- * Initialize all the managers & memory
- *
- ****/
-
- void InitMacintosh(void)
-
- {
- MaxApplZone();
-
- InitGraf(&thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- SysEnvirons(curSysEnvVers, &gMac);
-
- if (gMac.systemVersion < 0x0700)
- ExitToShell();
-
- }
- /* end InitMacintosh */
-
-
- /****
- * HandleMouseDown (theEvent)
- *
- * Take care of mouseDown events.
- *
- ****/
-
- void HandleMouseDown (EventRecord *theEvent)
-
- {
- WindowPtr theWindow;
- int windowCode = FindWindow (theEvent->where, &theWindow);
-
- switch (windowCode)
- {
- case inSysWindow:
- SystemClick (theEvent, theWindow);
- break;
-
- case inMenuBar:
- AdjustMenus();
- HandleMenu(MenuSelect(theEvent->where));
- break;
-
- case inDrag:
- if (theWindow == samplerWindow)
- DragWindow(samplerWindow, theEvent->where, &dragRect);
- break;
-
- case inContent:
- if (theWindow == samplerWindow)
- {
- short cntlPart;
- Point clickPt = theEvent->where;
- ControlHandle foundCntl;
-
- if (theWindow != FrontWindow())
- SelectWindow(samplerWindow);
- else
- {
- GlobalToLocal(&clickPt);
-
- cntlPart = FindControl(clickPt, samplerWindow, &foundCntl);
- if (cntlPart)
- {
- if (( foundCntl == rocketCntl)||( foundCntl == timeButtonCntl ))
- {
- if (cntlPart = TrackControl( foundCntl, clickPt, 0 ))
- {
- if ( foundCntl == rocketCntl)
- {
- SysBeep(20);
- }
- else if (foundCntl == timeButtonCntl)
- {
- SetCtlValue( timeButtonCntl, !GetCtlValue(timeButtonCntl));
-
- if (GetCtlValue( timeButtonCntl))
- {
- HiliteControl(timeCntl, 0);
- HiliteControl(dateCntl, 0);
- HiliteControl(numberCntl, 0);
- }
- else
- {
- HiliteControl(timeCntl, 255);
- HiliteControl(dateCntl, 255);
- HiliteControl(numberCntl, 255);
- }
-
- }
- }
- }
- else
- {
- if ( foundCntl == dateCntl)
- {
- SetCtlValue( timeCntl, 0 );
- HandleDateCDEFClick(clickPt);
- }
- else if ( foundCntl == timeCntl)
- {
- SetCtlValue( dateCntl, 0 );
- HandleTimeCDEFClick(clickPt);
- }
- else if ( foundCntl == numberCntl)
- {
- if (cntlPart = TrackControl( foundCntl, clickPt, NumCDEFProc ))
- {
- /* do nothing because NumCDEFProc() handles it */
- }
- }
- }
- }
- else
- {
- SetCtlValue( timeCntl, 0 );
- SetCtlValue( dateCntl, 0 );
- }
- }
-
-
- }
- break;
-
- case inGoAway:
- if (theWindow == samplerWindow &&
- TrackGoAway(samplerWindow, theEvent->where))
- HideWindow(samplerWindow);
- break;
- }
- }
- /* end HandleMouseDown */
-
-
- /****
- * HandleEvent()
- *
- * The main event dispatcher. This routine should be called
- * repeatedly (it handles only one event).
- *
- *****/
-
- void HandleEvent(void)
-
- {
- int ok;
- EventRecord theEvent;
- ControlHandle curCntl;
-
- HiliteMenu(0);
- SystemTask (); /* Handle desk accessories */
-
- ok = GetNextEvent (everyEvent, &theEvent);
- if (ok)
- switch (theEvent.what)
- {
- case mouseDown:
- HandleMouseDown(&theEvent);
- break;
-
- case keyDown:
- case autoKey:
- if ((theEvent.modifiers & cmdKey) != 0)
- {
- AdjustMenus();
- HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
- }
- break;
-
- case updateEvt:
- BeginUpdate(samplerWindow);
- DrawSampleWindow(((WindowPeek) samplerWindow)->hilited);
- EndUpdate(samplerWindow);
- break;
-
- case activateEvt:
- if (theEvent.modifiers & activeFlag)
- {
- HiliteControl(rocketCntl, 0);
- HiliteControl(timeButtonCntl, 0);
-
- if (GetCtlValue( timeButtonCntl))
- {
- HiliteControl(timeCntl, 0);
- HiliteControl(dateCntl, 0);
- HiliteControl(numberCntl, 0);
- }
- else
- {
- HiliteControl(timeCntl, 255);
- HiliteControl(dateCntl, 255);
- HiliteControl(numberCntl, 255);
- }
-
- }
- else
- {
- curCntl = ((WindowPeek)samplerWindow)->controlList;
- while (curCntl)
- {
- HiliteControl(curCntl, 255);
- curCntl = (*curCntl)->nextControl;
- }
- }
- break;
- }
- }
- /* end HandleEvent */
-
-
- /*****
- * main()
- *
- * This is where everything happens
- *
- *****/
-
-
- main()
-
- {
- InitMacintosh();
- SetUpMenus();
- SetUpWindow();
-
- for (;;)
- HandleEvent();
- }
- /* end main */